package com.modifiertech.lineage.handler;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import net.minecraft.entity.Entity;

//客户端范围选择处理器
public class ClientSelectedRangeHandler {
	//20tick 1s
    int maxInternal = 10;
    //数据清理检查节点执行间隔.
    int internal = 0;
	//全局客户端临时id存储
	private volatile ConcurrentHashMap<Entity,Long> tempEntityMap = new ConcurrentHashMap();
    //饿汉
    public static ClientSelectedRangeHandler INSTANCE=new ClientSelectedRangeHandler();
    private ClientSelectedRangeHandler(){
    }

    /**更新选框选中实体
     * 
     * @param str
     */
    public void update(Set<Entity> str) {
    	str.forEach(h->tempEntityMap.put(h,System.currentTimeMillis()));
    }
    
    /**高亮过期检查
     * 
     */
    public void overTimeCheck() {
        internal++;
        if (internal== maxInternal){
            internal=0;
            //执行遍历清理.
            Iterator<Map.Entry<Entity, Long>> i = tempEntityMap.entrySet().iterator();
            while(i.hasNext()) {
            	Map.Entry<Entity, Long> entity=i.next();
            	if(entity.getValue()<System.currentTimeMillis()-200){
            		//超过半秒,淘汰
            		entity.getKey().setGlowing(false);
            		i.remove();
            	}
            }
        }
    }
    
    
    
}
